import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_gift_animation_ctr.dart';
import 'package:xindong/models/gift/xindong_gift_chat_class.dart';
import 'package:xindong/routes/conversation/view/xindong_liaotian_message_score_container.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/utils/queue/xindong_svga_queue.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';

// 礼物项
class XinDongLiaoTianMessageGift extends StatelessWidget {
  final V2TimMessage message;
  final XinDongGiftChatClass model;
  final dynamic score;

  const XinDongLiaoTianMessageGift({Key? key, required this.message, required this.model, required this.score}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isFromSelf = message.isSelf ?? false;
    return XinDongLiaoTianMessageScoreContainer(
      hidden: isFromSelf,
      message: message,
      score: score,
      child: GestureDetector(
        onLongPress: () {
          if (TextUtil.isEmpty(model.cover_svga)) {
            showToast("礼物无特效");
            return;
          }
          XinDongGiftAnimationCtr.to.addQueue(SVGAClass(
            type: SVGAType.receiveGift,
            name: model.name,
            svga: model.cover_svga ?? "",
            allowDuplicates: false,
          ));
        },
        child: Container(
          height: 62,
          decoration: BoxDecoration(color: DZColors.white, borderRadius: BorderRadius.circular(10)),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            textDirection: isFromSelf ? TextDirection.rtl : TextDirection.ltr,
            children: [
              const SizedBox(width: 10),
              Flexible(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      model.name,
                      style: const TextStyle(color: DZColors.titleColor, fontSize: 14),
                    ),
                    Text(
                      "送出${model.name}x${model.num}",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(color: DZColors.placeholderColor, fontSize: 12),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 8.0, right: 8.0),
                child: ImageUtil.networkImageUrl(model.cover, width: 56, height: 56, placeholder: const SizedBox()),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
